package com.feixiu.mapreduce.writable;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class FlowMapper extends Mapper<LongWritable, Text, Text, FlowBean> {
    private FlowBean outV = new FlowBean();
    private Text outK = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //获取一行
        //1	13736230513	192.196.100.1	www.atguigu.com	2481	24681	200
        String line = value.toString();
        //切割
        String[] split = line.split("\t");
        //抓取想要数据
        String phone = split[1];
        //获取上行数据
        Long upFlow = Long.parseLong(split[split.length - 3]);
        //获取下行数据
        Long downFlow = Long.parseLong(split[split.length - 2]);
        //写入outV
        outV.setUpFlow(upFlow);
        outV.setDownFlow(downFlow);
        outV.setSumFlow();
        //写入outK
        outK.set(phone);

        context.write(outK, outV);

    }
}
